package com.shoeHouse.commodityCategory.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shoeHouse.commodityCategory.model.CommodityCategory;
import com.shoeHouse.commodityCategory.service.CommodifyCategoryService;
import com.shoeHouse.commodityInfo.model.CommodityInfo;
import com.shoeHouse.util.DataGrid;
import com.shoeHouse.util.PageHelper;

@Controller
@RequestMapping("/commodifyCategory")
public class CommodifyCategoryAction {
	@Autowired
	private CommodifyCategoryService categoryService;
	
	@ResponseBody
	@RequestMapping("/view")
	public DataGrid view(HttpServletRequest request,HttpServletResponse response,Integer page,Integer rows){
		
		//page表示当前页，rows表示一次查询的条数
		PageHelper pageHelper=new PageHelper();
		pageHelper.setCurrentPage(page);
		pageHelper.setPageSize(rows);
		//查询总数
		   DataGrid dataGrid=new DataGrid();
		  CommodityCategory category=new CommodityCategory();
		List<CommodityCategory> list=categoryService.getAll(category,pageHelper);
		int count=categoryService.count();
		dataGrid.setTotal(count);
		dataGrid.setRows(list);

		return dataGrid;
			
			
			
		}
	@RequestMapping("/treeView")
      public void TreeView(HttpServletRequest request,HttpServletResponse Response){
		//page表示当前页，rows表示一次查询的条数
				PageHelper pageHelper=new PageHelper();
				pageHelper.setCurrentPage(0);
				pageHelper.setPageSize(0);
				//查询总数
				   DataGrid dataGrid=new DataGrid();
				  CommodityCategory category=new CommodityCategory();
				List<CommodityCategory> list=categoryService.getAll(category,pageHelper);
				CategoryTreeUtil treeUtil=new CategoryTreeUtil();
				String Json=treeUtil.TreeUtil(list,"0");
				try {
					Response.setCharacterEncoding("UTF-8");
					Response.setContentType("text/json");
					Response.getWriter().append(Json);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
    	  
      }
}
